#include <iostream>
#include <memory>

// 4
class Girl;
class Boy
{
public:
    Boy() { std::cout << "Boy构造\n"; }
    ~Boy() { std::cout << "Boy析构\n"; }
    void SetGirlFirend(std::shared_ptr<Girl> &girl)
    {
        this->girlFirend = girl;
    }

private:
    std::shared_ptr<Girl> girlFirend;
    // std::weak_ptr<Girl> girlFirend;
};

class Girl
{
public:
    Girl() { std::cout << "Girl构造\n"; }
    ~Girl() { std::cout << "Girl析构\n"; }
    void SetBoyFirend(std::shared_ptr<Boy> &boy)
    {
        this->boyFirend = boy;
    }

private:
    // std::shared_ptr<Boy> boyFirend;
    std::weak_ptr<Boy> boyFirend;
};

int main()
{
    std::shared_ptr<Boy> b = std::make_shared<Boy>();
    std::shared_ptr<Girl> g = std::make_shared<Girl>();

    b->SetGirlFirend(g);
    g->SetBoyFirend(b);
}

// 弱指针:解决共享指针的循环引用问题
